package com.sgb.kjwl.view.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.DialogTeamPublishBinding;
import com.swgk.core.view.entity.MenuEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.view.ui.activity.self.packers.LaborServiceAndEmploymentPublishActivity;
import com.sgb.kjwl.view.ui.activity.self.packers.SelfTeamEmploymentEditActivity;
import com.sgb.kjwl.view.ui.activity.self.packers.SelfTeamIntroduceActivity;
import com.sgb.kjwl.view.ui.activity.self.packers.SelfWorkerPublishActivity;
import com.sgb.kjwl.view.ui.adapter.TeamPublishAdapter;

import org.jetbrains.annotations.NotNull;

import java.util.List;
/**
 * @author: 王彬臣
 * @date: 2021/8/18
 * @Description: 工队发布Dialog
 */
public class TeamPublishDialog extends Dialog implements View.OnClickListener{
    DialogTeamPublishBinding mBinding;
    List<MenuEntity> menuEntityList;
    TeamPublishAdapter mAdapter;
    public TeamPublishDialog(@NonNull @NotNull Context context,List<MenuEntity> menuEntityList) {
        super(context, R.style.RoundCornerDialog);
        mBinding= DataBindingUtil.inflate(LayoutInflater.from(context),R.layout.dialog_team_publish,null, false);
        setContentView(mBinding.getRoot());
        this.menuEntityList=menuEntityList;
        init();
        Window window = getWindow();
        if (window != null) {
            WindowManager.LayoutParams params = window.getAttributes();
            params.gravity = Gravity.CENTER;
            window.setAttributes(params);
        }
    }

    private void init() {
        mBinding.setOnClick(this);
        mBinding.menuView.setLayoutManager(new GridLayoutManager(getContext(),2));
        mAdapter= new TeamPublishAdapter(menuEntityList);
        mBinding.menuView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            MenuEntity entity=menuEntityList.get(position);
            switch (entity.getName()) {
                case "工人发布":
                    SelfWorkerPublishActivity.start(getContext());
                    break;
                case "用工发布":
                    ActivityJump.jumpToActivity(getContext(), SelfTeamEmploymentEditActivity.class);
                    break;
                case "劳务发布":
                    ActivityJump.jumpToActivity(getContext(), LaborServiceAndEmploymentPublishActivity.class);
                    break;
                case "工队发布":
                    SelfTeamIntroduceActivity.start(getContext(), null, AppConstant.PAGER_ADD);
                    break;
                default:
                    break;
            }
        });
    }

    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.iv_close){
            dismiss();
        }

    }

}
